package com.qxp.simplerpc.parse;

import com.qxp.simplerpc.entity.CommonProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

/**
 * @author qianxp
 */
public class URLParse {
    // logger
    private static final Logger logger = LoggerFactory.getLogger(URLParse.class);

    //127.0.0.1:8007
    public static CommonProperties parseURL(String url) {
        if (StringUtils.isEmpty(url) || !url.contains(":")) {
            //throw new RpcException("");
            logger.error("url illeagell,parse error...");
            return new CommonProperties();
        }
        CommonProperties commonProperties = new CommonProperties();
        commonProperties.setPort(Integer.parseInt(url.substring(url.indexOf(":") + 1)));
        commonProperties.setHost(url.substring(0, url.indexOf(":")));
        return commonProperties;
    }


}
